import requests,re,json
from  missav.m3u8_parse import down12345,get_headers

headers = get_headers()



def down_one(s1):
    # s1 = "https://xiaoyakankan.com/post/0f39f9d0b4.html?vod=148_40045-0"
    s = requests.get(s1, headers=headers,timeout=100, verify=False)

    # print(s.text)

    # <script>var post = {"id":48339,"lang":"cn","name":"\u7231\u4e4b\u5973\u5deb","vods":[{"id":"148_40045","name":"\u7ebf\u8def148\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":8447,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/hd.ijycnd.com\/play\/neg7zZZe\/index.m3u8"]]},{"id":"166_31936","name":"\u7ebf\u8def166\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":9364,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/play.hhuus.com\/play\/rb2JKWWb\/index.m3u8"]]},{"id":"135_14810","name":"\u7ebf\u8def135\uff1a\u7231\u4e4b\u5973\u5deb[\u4e2d\u82f1\u53cc\u5b57]","ttl":8568,"resLabel":"720p","source":[["HD","https:\/\/jpzy01.com\/20230707\/DLNu2g1m\/index.m3u8"]]},{"id":"158_18760","name":"\u7ebf\u8def158\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":9461,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/cdn.wlcdn99.com:777\/20220414\/8kfFOLHi\/index.m3u8"]]},{"id":"167_8680","name":"\u7ebf\u8def167\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":9373,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/1080p.huyall.com\/play\/neg7zZZe\/index.m3u8"]]},{"id":"32_61924","name":"\u7ebf\u8def32\uff1a\u7231\u4e4b\u5973\u5deb[HD]","ttl":8631,"resLabel":"720p","source":[["HD","https:\/\/v8.fentvoss.com\/sdv8\/202401\/23\/AJ7HdLPeC51\/video\/index.m3u8"]]},{"id":"146_61924","name":"\u7ebf\u8def146\uff1a\u7231\u4e4b\u5973\u5deb[HD]","ttl":9123,"resLabel":"720p","source":[["HD","https:\/\/v8.longshengtea.com\/yyv8\/202401\/23\/AJ7HdLPeC51\/video\/index.m3u8"]]},{"id":"36_61924","name":"\u7ebf\u8def36\uff1a\u7231\u4e4b\u5973\u5deb[HD]","ttl":8659,"resLabel":"720p","source":[["HD","https:\/\/v8.wxys10086.com\/yyv8\/202401\/23\/AJ7HdLPeC51\/video\/index.m3u8"]]},{"id":"197_17515","name":"\u7ebf\u8def197\uff1a\u7231\u4e4b\u5973\u5deb","ttl":8684,"resLabel":"720p","source":[["\u7b2c01\u96c6","https:\/\/api.heimuer.app\/play\/776dbf36185c4c83a602c0b355fe6c39.m3u8"]]},{"id":"164_1067","name":"\u7ebf\u8def164\uff1a\u7231\u4e4b\u5973\u5deb[\u5df2\u5b8c\u7ed3]","ttl":16567,"resLabel":"480p","source":[["HD\u4e2d\u5b57","https:\/\/s1.bfllvip.com\/video\/aizhinvwu\/HD\u4e2d\u5b57\/index.m3u8"]]},{"id":"22_67804","name":"\u7ebf\u8def22\uff1a\u7231\u4e4b\u5973\u5deb[HD]","ttl":16919,"resLabel":"","source":[["HD","https:\/\/v8.tlkqc.com\/wjv8\/202401\/23\/AJ7HdLPeC51\/video\/index.m3u8"]]},{"id":"147_73119","name":"\u7ebf\u8def147\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":17479,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/v.gsuus.com\/play\/Pe9ORBbL\/index.m3u8"]]},{"id":"148_25190","name":"\u7ebf\u8def148\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":18547,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/hd.ijycnd.com\/play\/neg61Gdw\/index.m3u8"]]},{"id":"163_67804","name":"\u7ebf\u8def163\uff1a\u7231\u4e4b\u5973\u5deb[HD]","ttl":24912,"resLabel":"720p","source":[["HD","https:\/\/v8.tlkqc.com\/wjv8\/202401\/23\/AJ7HdLPeC51\/video\/index.m3u8"]]},{"id":"166_32465","name":"\u7ebf\u8def166\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":25652,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/play.hhuus.com\/play\/lej6WvBe\/index.m3u8"]]},{"id":"147_94820","name":"\u7ebf\u8def147\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":33008,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/v.gsuus.com\/play\/Pe93418b\/index.m3u8"]]},{"id":"19_105668","name":"\u7ebf\u8def19\uff1a\u7231\u4e4b\u5973\u5deb[HD]","ttl":36540,"resLabel":"720p","source":[["HD","https:\/\/v3.dious.cc\/20220401\/k04VraUc\/index.m3u8"]]},{"id":"187_14831","name":"\u7ebf\u8def187\uff1a\u7231\u4e4b\u5973\u5deb[HD\u4e2d\u5b57]","ttl":41304,"resLabel":"480p","source":[["HD\u4e2d\u5b57","https:\/\/vip.ffzy-play8.com\/20221117\/455_b4f9f30b\/index.m3u8"]]},{"id":"150_10877","name":"\u7ebf\u8def150\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":41387,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/bfikuncdn.com\/20221010\/QIqhm3X1\/index.m3u8"]]},{"id":"134_53076","name":"\u7ebf\u8def134\uff1a\u7231\u4e4b\u5973\u5deb[HD]","ttl":42800,"resLabel":"720p","source":[["HD","https:\/\/vod12.wgslsw.com\/20240413\/BkRxuEYV\/index.m3u8"]]},{"id":"167_36702","name":"\u7ebf\u8def167\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":44227,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/1080p.huyall.com\/play\/neg61Gdw\/index.m3u8"]]},{"id":"168_1908","name":"\u7ebf\u8def168\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":53282,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/play.subokk.com\/play\/Xe0AQYVa\/index.m3u8"]]},{"id":"31_17718","name":"\u7ebf\u8def31\uff1a\u7231\u4e4b\u5973\u5deb[\u8d85\u6e05]","ttl":55485,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/ukzy.ukubf4.com\/20220408\/5UVTHOsF\/index.m3u8"]]},{"id":"149_67694","name":"\u7ebf\u8def149\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":62745,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/play.xluuss.com\/play\/Xe0Ovydx\/index.m3u8"]]},{"id":"25_50240","name":"\u7ebf\u8def25\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":66459,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/hn.bfvvs.com\/play\/yb8OPgav\/index.m3u8"]]},{"id":"160_40407","name":"\u7ebf\u8def160\uff1a\u7231\u4e4b\u5973\u5deb[HD]","ttl":67622,"resLabel":"720p","source":[["HD\u4e2d\u5b57","https:\/\/vip.lz-cdn3.com\/20221121\/16148_c39b582c\/index.m3u8"]]},{"id":"25_71371","name":"\u7ebf\u8def25\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":67857,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/hn.bfvvs.com\/play\/yb8X412b\/index.m3u8"]]},{"id":"180_61924","name":"\u7ebf\u8def180\uff1a\u7231\u4e4b\u5973\u5deb[HD]","ttl":74604,"resLabel":"720p","source":[["HD","https:\/\/v8.mzxay.com\/202401\/23\/AJ7HdLPeC51\/video\/index.m3u8"]]},{"id":"170_15085","name":"\u7ebf\u8def170\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":78045,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/vv.jisuzyv.com\/play\/Le3JLw9d\/index.m3u8"]]},{"id":"143_25356","name":"\u7ebf\u8def143\uff1a\u7231\u4e4b\u5973\u5deb[HD]","ttl":79416,"resLabel":"720p","source":[["HD","https:\/\/v.ykv3.com\/20240424\/VvOdxzjV\/index.m3u8"]]},{"id":"144_30132","name":"\u7ebf\u8def144\uff1a\u7231\u4e4b\u5973\u5deb[HD]","ttl":84316,"resLabel":"720p","source":[["HD","https:\/\/v.ykv3.com\/20240424\/VvOdxzjV\/index.m3u8"]]},{"id":"149_91778","name":"\u7ebf\u8def149\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":84956,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/play.xluuss.com\/play\/Xe0AQYVa\/index.m3u8"]]},{"id":"170_7365","name":"\u7ebf\u8def170\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":85062,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/vv.jisuzyv.com\/play\/mbkXWwKd\/index.m3u8"]]},{"id":"168_51869","name":"\u7ebf\u8def168\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":85924,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/play.subokk.com\/play\/Xe0Ovydx\/index.m3u8"]]},{"id":"154_45785","name":"\u7ebf\u8def154\uff1a\u7231\u4e4b\u5973\u5deb[HD\u4e2d\u5b57]","ttl":93802,"resLabel":"720p","source":[["HD\u4e2d\u5b57","https:\/\/vip15.play-cdn15.com\/20230911\/24607_5b04f390\/index.m3u8"]]},{"id":"194_5299","name":"\u7ebf\u8def194\uff1a\u7231\u4e4b\u5973\u5deb[HD]","ttl":94581,"resLabel":"720p","source":[["HD","https:\/\/v.ykv3.com\/20240424\/VvOdxzjV\/index.m3u8"]]},{"id":"21_50865","name":"\u7ebf\u8def21\uff1a\u7231\u4e4b\u5973\u5deb[\u6b63\u7247]","ttl":99388,"resLabel":"720p","source":[["\u6b63\u7247","https:\/\/ll.bdzybf11.com\/20220405\/VGUYlHIN\/index.m3u8"]]},{"id":"181_52678","name":"\u7ebf\u8def181\uff1a\u7231\u4e4b\u5973\u5deb[HD\u4e2d\u5b57]","ttl":184679,"resLabel":"\u53ef\u80fd\u65e0\u6cd5\u64ad\u653e","source":[["HD\u4e2d\u5b57","https:\/\/vip.kuaikan-play2.com\/20230402\/pcZvNCsP\/index.m3u8"]]}],"i18n":{"loading":"\u75af\u72c2\u52a0\u8f7d\u4e2d... \u82e5\u4e0d\u81ea\u52a8\u64ad\u653e\uff0c\u8bf7\u624b\u52a8\u70b9\u51fb\u64ad\u653e\u6309\u94ae","bad":"\u5dee","overtime":"\u8d85\u65f6","overtimeTip":"\u64ad\u653e\u5931\u8d25\u4e86\uff0c\u8bd5\u8bd5\u5176\u5b83\u7684\u7ebf\u8def\u5427"}};</script>

    res_text = s.text

    s = re.findall('<script>var post =(.*?)</script>', res_text)
    # {"id":48339,"lang":"cn","name": "xxx"} s[0]
    # print(s[0])
    #
    # s = "\'" +s[0]+"\'"
    s = s[0].split(';')[0]
    print(s)
    s = json.loads(s)
    print()

    for vod in s['vods']:
        try:
            # print()
            name = vod['name']
            if "：" in name:
                name=name.split('：')[-1].strip()

            if ":" in name:
                name = name.replace(":","_")
            if "[" in name:
                name = name.split("[")[0]

            print("filename",name)
            url = vod['source'][0][-1]
            # print(url)

            down12345(url, name)
            break
        except Exception as e:
            print("down12345", e)
            continue

def get_video_list():
    # 福利首页
    url="https://xiaoyakankan.com/cat/15.html"


# s1 = "https://xiaoyakankan.com/post/0f39f9d0b4.html?vod=148_40045-0"
# s1 = "https://xiaoyakankan.com/post/d11412ebaa.html"
# s1 = "https://www.fofoyy.com/dianying/103654"

from missav.test_sql1 import cur,con
# res = cur.execute("SELECT * FROM movie")
# for i in res.fetchall():
#     print(i)
# down_one(s1)

cursor = cur
def query_page(conn, page, size):
    cursor = cur

    # 计算总条数
    cursor.execute('SELECT COUNT(*) FROM movie')
    total = cursor.fetchone()[0]

    # 查询分页数据
    cursor.execute('SELECT * FROM movie where name="欧洲情色片" LIMIT ? OFFSET ? ', (size, (page-1)*size))
    data = cursor.fetchall()


    return total, data


# print(query_page(con,1,10)[1])

# data = query_page(con,1,10)[-1]
# # data = query_page(con,1,10)[-1]
#
# for i in data:
#     print(i[2])
    # down_one(i[2])


data = query_page(con,3,10)[-1]

for i in data:
    print(i[2])
    down_one(i[2])

cursor.close()





# s="https://vip.kuaikan-play1.com/20230308/G5pwwH8E/index.m3u8"
# s2="十年爱"
#
# down12345(s, s2)